<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    // 匿名函数
    var fn1 =() => {
        console.log("fn1");
    }
    fn1();

    // 命名函数
    function fn2(){
        console.log("fn2");
    }
    fn2();

    // 箭头函数传参
    var fn = (a,b) => {
        console.log(a,b);
    }
    fn(1,2);

    var fn3 = a => {
        console.log(a);
    }
    fn3(1);

    // 可以改造有返还值的函数
    var fn4 = (a,b) => {
        return a + b;
    }
    console.log(fn4(1,2));

    var fn5 = (a,b) => a+b;
    console.log(fn5(1,2));

    // 避免大括号歧义
    var fn6 = () => {
        return{name:"abc",age:20}
    };
    console.log(fn6());

    var arr = ["abc","def","hg"];
    var arr1 = arr.map(function(item){
        return item+"?"
    })

    var arr2 = arr.map(item => item + "?");

    console.log(arr1);
    console.log(arr2);


    var users = [{
        name:"张三",
        age:20,
        gender:"男"
    },{
        name:"张三2",
        age:26,
        gender:"男"
    },{
        name:"张三3",
        age:19,
        gender:"男"
    },{
        name:"张三4",
        age:20,
        gender:"男"
    },{
        name:"张三5",
        age:24,
        gender:"女"
    },{
        name:"张三6",
        age:23,
        gender:"男"
    }]
    // 需要在用户里筛选 ： 所有的男性 ， 年龄大于20岁 ，名字前加上 名字:张三1
    var arr3 = users.filter(item => item.gender === "男");
    console.log(arr3);
    var arr4 = arr3.filter(item => item.age >= 20);
    console.log(arr4);
    var arr5 = arr4.map(item =>({
        name:"姓名：" + item.name,
        age:item.age,
        gender:item.gender
    }))
    console.log(arr5);

    var res = users.filter(item => item.gender === "男").filter(item => item.age >= 20).map(item =>({
        name:"姓名：" + item.name,
        age:item.age,
        gender:item.gender
    }))
    console.log(res);
</script>